package com.esm.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.esm.dao.SelectWalfareDao_zxk;
import com.esm.model.Walfare;
import com.esm.utils.JDBCUtil;

/**
 * 获取福利 Dao实现
 * @author 康少
 *
 * 2017年1月9日
 */
public class SelectWalfareDaoImpl_zxk implements SelectWalfareDao_zxk{

	public List<Walfare> getWalfareByUname(String Uname) {
		// TODO Auto-generated method stub
		List<Walfare> walfares = new ArrayList<Walfare>();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT ems_walfare.wid,ems_walfare.wname");
		sql.append(" FROM ems_user");
		sql.append(" INNER JOIN ems_user_wal");
		sql.append(" ON ems_user.uid = ems_user_wal.uid");
		sql.append(" INNER JOIN ems_walfare");
		sql.append(" ON ems_walfare.wid = ems_user_wal.wid");
		sql.append(" WHERE ems_user.uname = ?");
		Connection con = JDBCUtil.getConnection();
		PreparedStatement pst = null;
		try {
			pst = con.prepareStatement(sql.toString());
			pst.setString(1, Uname);
			ResultSet rs = pst.executeQuery();
			while (rs.next()) {
				Walfare walfare = new Walfare();
				walfare.setWid(rs.getInt("wid"));
				walfare.setWname(rs.getString("wname"));
				walfares.add(walfare);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JDBCUtil.closeJDBC(pst, con);
		return walfares;
	}

}
